import time


class GeneratorDemo:
    def work1(self):
        while True:
            print('---work1---')
            yield
            time.sleep(0.2)

    def work2(self):
        while True:
            print('---work2---')
            yield
            time.sleep(0.2)

    def fib(self, n):
        num1, num2 = 0, 1
        curpos = 0
        while curpos < n:
            result = num1
            num1, num2 = num2, num1 + num2
            yield result
        return 'done'

    def _test_next(self):
        """
        gd = GeneratorDemo()
        gd._test_next()
        """
        w1 = self.work1()
        w2 = self.work2()
        while True:
            next(w1)
            next(w2)

    def _test_next_for(self):
        """
        gd = GeneratorDemo()
        gd._test_next_for()
        """
        f = self.fib(5)
        for i in range(5):
            print(next(f))

    def _test_send(self):
        """
        gd = GeneratorDemo()
        gd._test_send()
        """
        f = self.fib(5)
        for i in range(5):
            print(f.send(None))


if __name__ == '__main__':
    gd = GeneratorDemo()
    gd._test_send()
